/**
 * @author Caius
 * @description
 * @version 1.0
 * @since Created in 2025-02-08
 */

package com.itsense.stock.utils;

import com.itsense.stock.pojo.domain.PermissionTreeDomain;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TreeUtil {
    public static List<HashMap> buildPermissionTree(Map<Long, PermissionTreeDomain> permissionMap, Long parentId , Integer count, List<HashMap> treeList) {
        // 创建列表用于保存数据

        // 循环查询是否有符合条件的数据
        for (Map.Entry<Long, PermissionTreeDomain> entry : permissionMap.entrySet()) {
            PermissionTreeDomain permissionDomain = entry.getValue();
            // 如何Id== pid 则获取到了
            if (parentId.equals(permissionDomain.getPid())) { // 假设PermissonTreeDomian类中有一个getPid()方法返回父ID

                String title = permissionDomain.getTitle();
                Long id = permissionDomain.getId();
                HashMap<String, Object> map = new HashMap<>();
                map.put("id" , id);
                map.put("title" , title);
                map.put("count" , count);

                treeList.add(map);
                buildPermissionTree(permissionMap, permissionDomain.getId(),count+1,treeList);
            }
        }

        return treeList;
    }
}
